package demo.practice.leetcode;


class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}

public class Ms0202 {
    private ListNode klast;

    public int kthToLast(ListNode head, int k) {
        //1假设第一个节点就是倒数第k个节点
        klast=head;
        for(int i=1;i<k;i++){
            head=head.next;
        }
        while (head.next!=null){
            klast=klast.next;
            head=head.next;
        }
        //
        return klast.val;
    }
}
